$(document).ready(function()
    {
        $.table_master = null;
        
        $.init_master = function()
        {
            $.ajax({
                url: base_url + 'br-02/perkiraan/get_all',
                type: 'post',
                success : function(data)
                {
                    $.table_master = $('#kredit_table').dataTable({
                        "bJQueryUI": true,
                        "sPaginationType": "full_numbers",
                        "aaData": data.data,
                        "bDestroy": true,
                        "aoColumns":[
                                
                                    {'sTitle' : 'ID Perkiraan', 'mDataProp' : 'KODE_PERKIRAAN'},

                                    {'sTitle' : 'Jenis Perkiraan', 'mDataProp' : 'JENIS'},

                                    {'sTitle' : 'Perkiraan', 'mDataProp' : 'URAIAN_PERKIRAAN'},

                                   
							
                            ]
                    });
                },
                error: function(res)
                {
                    alert(res.responseText);
                },
                dataType: 'json'
            });
        }
        $.init_master();

   
        $('#kredit_dialog').dialog({
            title: 'Data perkiraan',
            width: '950px',
            autoOpen:false,
            modal:true,
            resizable:false
        });

        $.resultkredit = function(data)
                {
                    if($('td:first', data).html() != 'No matching records found')
                    {
                        $("#ID_KREDIT").val($('td:first', data).html());
                        $("#KREDIT").val($('td:eq(2)', data).html());
                    }
                }

        $('#kredit_table tbody tr').live('click', function()
        {
            $.datatablekreditRowClicked(this);
        });

        $.datatablekreditRowClicked = function(that)
        {
            $.resultkredit(that);
            $('#kredit_dialog').dialog('close');
        }

        $('#KREDIT').click(function(){
            $("#JUMLAH_KREDIT").val($("#JUMLAH_DEBIT").val());
            $('#kredit_dialog').dialog('open');
        });
        

        

    });